//
//  UIColor+Extension.h
//
//  Created by 陈锐新 on 16/6/1.
//  Copyright © 2016年 . All rights reserved.
//

#import "ColorHexExtension.h"

@implementation UIColor (HexExtension)

+ (UIColor*)hex:(NSUInteger)hexValue
{
    Byte alphaHex = (hexValue >> 24) & 0xFF;
    Byte redHex = (hexValue >> 16) & 0xFF;
    Byte greenHex = (hexValue >> 8) & 0xFF;
    Byte blueHex = hexValue & 0xFF;
    
    CGFloat red = redHex/255.f;
    CGFloat green = greenHex/255.f;
    CGFloat blue = blueHex/255.f;
    CGFloat alpha = (alphaHex==0) ? 1:(alphaHex/255.f);
    
    return [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
}

/// 随机生成一个颜色
+ (UIColor *)randomColor {
    NSInteger r,g,b;
    r = arc4random()%255;
    g = arc4random()%255;
    b = arc4random()%255;
    return [UIColor colorWithRed:r/255.f green:g/255.f blue:b/255.f alpha:1.f];
}

//- (void)getR:(float *)r G:(float *)g B:(float *)b A:(float *)alpha{
//    const CGFloat *components;
//    components = CGColorGetComponents(self.CGColor);
//    //    for (int i = 0; i < CGColorGetNumberOfComponents(self.CGColor); i++) {
//    //        NSLog(@"%f",components[i]);
//    //    }
//    *r = components[0];
//    *g = components[1];
//    *b = components[2];
//    *alpha = components[3];
//}

@end
